#ifndef F_CAClientC_h
#define F_CAClientC_h

// ***********************************************************************

// class EDROOMTopContext

// ***********************************************************************



class EDROOMTopContext {

protected:

enum EDROOMCAClientSignal { EDROOMSignalTimeout, EDROOMSignalDestroy, SResAck, SResNack, SResReq, SFreeRes };


	friend class CAClient;

	CAClient &EDROOMcomponent;

	CEDROOMMessage * &Msg;

	CEDROOMMessage * &MsgBack;

	//Parameter

	CDClientConfig & EDROOMParameter;


	//Ports

	CEDROOMInterface & pServReq;
	CEDROOMTimingInterface & ResConfigTimer;
	CEDROOMTimingInterface & Timer;

	enum edroomStateId{I, Idle, WaitingRes, Working};

	enum IdTrans{Init, ReqRes, ReqRes_Nack, ReqRes_Ack, FreeRes, TryAgain, TryAgain_Nack, TryAgain_Ack,  EDROOMMEMORIA };

	//Constantes



	//Variables

	TEDROOMBool &VresAck;
	TEDROOMUInt8 &Vresld;


	//Pool

	class CEDROOMPOOLTEDROOMUInt8:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLTEDROOMUInt8(TEDROOMUInt32 elemCount,TEDROOMUInt8 *pMem, TEDROOMBool *pMarks);
		TEDROOMUInt8	* AllocData();
	};
	CEDROOMPOOLTEDROOMUInt8	& EDROOMPoolTEDROOMUInt8;


	// CONSTRUCTORES

	EDROOMTopContext (CAClient &act, TEDROOMBool & EDROOMpVarVresAck, TEDROOMUInt8 & EDROOMpVarVresld, CEDROOMPOOLTEDROOMUInt8 & EDROOMpPoolTEDROOMUInt8 );

	EDROOMTopContext ( EDROOMTopContext &contex );

public:

	bool EDROOMSearchContextTrans(TEDROOMTransId &edroomCurrentTrans);

	void EDROOMNuevoMens () { EDROOMcomponent.EDROOMNewMsg(); }

	// Funciones Definidas por el usuario

	void	FFreeRequest();

	void	FFreeRes();

	void	FProgRequest();

	void	FProgWait();

	void	FProgWork();

	void	FResRequest();

};

// ***********************************************************************

// class EDROOM_CTX_Working_3

// ***********************************************************************



class EDROOM_CTX_Working_3 : public EDROOMTopContext {

protected:
	enum edroomStateId{ResConfig, DoWork};

	enum IdTrans{ToResConfig, ToResConfig2, TryResConfig, TryResConfig_ResConfigError, TryResConfig_ResConfigOK,  EDROOMMEMORIA };

	//Constantes



	//Variables

	TEDROOMBool &VresConfigOK;


	// CONSTRUCTORES

	EDROOM_CTX_Working_3( EDROOMTopContext &contex, TEDROOMBool & EDROOMpVarVresConfigOK );

	EDROOM_CTX_Working_3( EDROOM_CTX_Working_3 &contex );

public:
	bool EDROOMSearchContextTrans(TEDROOMTransId &edroomCurrentTrans);

	// Funciones Definidas por el usuario

	void	FProgResConfig();

	void	FResConfigOK();

	void	FTryResConfig();

};

// ***********************************************************************

// class EDROOM_SUB_Working_3

// ***********************************************************************



class EDROOM_SUB_Working_3:public EDROOM_CTX_Working_3{ 

protected:



	EDROOM_CTX_Working_3::edroomStateId edroomCurrentState;

	EDROOM_CTX_Working_3::edroomStateId edroomNextState;

	//Variables

	TEDROOMBool VresConfigOK;
public:

	EDROOMTopContext::edroomStateId idEstado;

	// CONSTRUCTOR*************************************************

	EDROOM_SUB_Working_3(EDROOMTopContext::edroomStateId idEst, EDROOMTopContext &contex );

	// llegada*************************************************

	TEDROOMTransId llegada(EDROOMTopContext::IdTrans );

	// Inicio**********************************************

	void EDROOMInicio();

	// ***********************************************************************

	// SubEstado Hoja ResConfig

	// ***********************************************************************



	TEDROOMTransId EDROOMResConfigllegada();

	// ***********************************************************************

	// SubEstado Hoja DoWork

	// ***********************************************************************



	TEDROOMTransId EDROOMDoWorkllegada();

};

// ***********************************************************************

// class EDROOMTopState

// ***********************************************************************



class EDROOMTopState : public EDROOMTopContext {

protected:

	EDROOM_SUB_Working_3 EDROOMWorking;


	EDROOMTopContext::edroomStateId edroomCurrentState;

	EDROOMTopContext::edroomStateId edroomNextState;

	//Variables

	TEDROOMBool VresAck;
	TEDROOMUInt8 Vresld;


	//Pools

	CEDROOMPOOLTEDROOMUInt8	EDROOMPoolTEDROOMUInt8;


public:

	// CONSTRUCTOR

	EDROOMTopState (CAClient &act, CEDROOMMemory *pEDROOMMemory  );


	// EDROOMBehaviour**********************************************

	void EDROOMBehaviour();

	// Inicio**********************************************

	void EDROOMInicio();

	// ***********************************************************************

	// SubEstado Inicial 

	// ***********************************************************************



	TEDROOMTransId EDROOMIllegada();

	// ***********************************************************************

	// SubEstado Hoja Idle

	// ***********************************************************************



	TEDROOMTransId EDROOMIdlellegada();

	// ***********************************************************************

	// SubEstado Hoja WaitingRes

	// ***********************************************************************



	TEDROOMTransId EDROOMWaitingResllegada();

};


#endif
